package cn.bytecollege.admin.controller;

import cn.bytecollege.admin.service.OrderDetailService;
import cn.bytecollege.common.constant.Resource;
import cn.bytecollege.common.entity.OrderDetail;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author NJK
 */
@WebServlet(name = "OrderDetailListController",value = "/admin/orderDetailList")
public class OrderDetailListController extends HttpServlet {
    private OrderDetailService orderDetailService =null;
    public OrderDetailListController(){
        orderDetailService = new OrderDetailService();
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String orderNumber = req.getParameter("orderNumber");
        String totalPrice = String.valueOf(orderDetailService.calculatePriceByOrderNumber(orderNumber));
        List<OrderDetail> list = orderDetailService.findByOrderNumber(orderNumber);
        req.setAttribute("totalPrice",totalPrice);
        req.setAttribute("list",list);
        req.getRequestDispatcher(Resource.PAGE_LOCATION+"/admin/OrderDetailList.jsp").forward(req,resp);
    }
}
